﻿Imports Training.Common

Partial Public Class Video
    Inherits System.Web.UI.Page
    Public fNameWExt As String ' filename with extension
    Public fName As String ' filename
    Public vName As String ' videoname

    ''' <summary>
    ''' Page load event, make sure querystring data is present
    ''' get video information on load
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsNothing(Request.QueryString("vif")) Then
            ' call function to get video information
            SetVideoInfo(Request.QueryString("vif"))
        Else
            Response.Write("Data required to run this page is missing. Please close window.")
        End If
    End Sub

    ''' <summary>
    ''' Set variables with information from video
    ''' </summary>
    ''' <param name="vif"></param>
    ''' <remarks></remarks>
    Private Sub SetVideoInfo(ByVal vif As Integer)
        Dim vTable As DataTable = GetVideoInfo(vif)
        Dim fmt As String

        ' initial value of fmt
        fmt = ".wmv"

        ' load variables from datatable
        For Each row As DataRow In vTable.Rows
            fmt = row("Format")
            fNameWExt = row("FilePath")
            fName = Replace(fNameWExt, Right(fNameWExt, 4), "")
            vName = row("VideoName")
        Next

        ' show/hide div based on file format
        Select Case fmt
            Case ".swf"
                flasher.Visible = True
                wmvdiv.Visible = False
                err.Visible = False
            Case ".wmv"
                flasher.Visible = False
                wmvdiv.Visible = True
                err.Visible = False
            Case ".pdf"
                Response.Redirect("video/" & fNameWExt)
            Case Else
                flasher.Visible = False
                wmvdiv.Visible = False
                err.Visible = True
        End Select

    End Sub

End Class